import 'package:flutter/material.dart';
class AnimationBallWidget extends StatefulWidget {
  final Offset startOffset;
  final Offset endOffset;
  final int animationTime;

  AnimationBallWidget(
      {required this.startOffset,
        required this.endOffset,
        required this.animationTime});

  @override
  _AnimationBallWidgetState createState() => _AnimationBallWidgetState();
}

class _AnimationBallWidgetState extends State<AnimationBallWidget>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<Offset> _animation;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: Duration(milliseconds: widget.animationTime),
      vsync: this,
    );
    _animation = Tween<Offset>(
      begin: widget.startOffset,
      end: widget.endOffset,
    ).animate(_controller);
    _controller.forward();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: _animation,
      builder: (context, child) {
        return Positioned(
          left: _animation.value.dx,
          top: _animation.value.dy,
          child: Container(
            width: 20,
            height: 20,
            decoration: BoxDecoration(
              color: Color(0xffc80815),
              // gradient: LinearGradient(
              //   colors: [
              //     Color(0xffE873FF),
              //     Color(0xffFFC077),
              //   ],
              // ),
              shape: BoxShape.circle,
            ),
          ),
        );
      },
    );
  }
}